1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : suchmaschine/classes/class.pluginhtm.inc.php
5 : - Modulgruppe: Suche
6 : - Beschreibung: In dieser Datei wird die Klasse PluginPDF implementiert.
7 : - Version: 0.1 01/08/08
8 : - Autor(en): Jörg Rieger
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 : /**
24 : * Path to Root falls nicht gesetzt
25 : */
26 : if (!defined('PATH_TO_ROOT')) {
27 : define("PATH_TO_ROOT", "../../");
28 :
29 : require_once('class.iindexer.inc.php');
30 : require_once('class.indexer.inc.php');
31 : }
32 :
33 : /**
34 : * Klasse PluginHtm
35 : *
36 : * @package eStudy.Suchmaschine
37 : * @version 0.1 01/08/08
38 : * @author Jörg Rieger
39 : */
40 :
41 : define('PDF_MAGIC', "\\x25\\x50\\x44\\x46\\x2D");
42 :
43 : class PluginPDF extends Indexer {
44 :
45 : private $fileName = '';
46 :
47 : /**
48 : * Kontruktor
49 : *
50 : * @access public
51 : */
52 : public function __construct() {
53 0 : $this->name = 'PDF';
54 :
55 0 : $this->fileExt = array(
56 : "pdf"
57 0 : );
58 0 : }
59 :
60 : /**
61 : * Öffnen der Datei
62 : *
63 : * @access public
64 : */
65 : public function open( $fileName ) {
66 0 : if ( !file_exists($fileName) )
67 0 : throw new Exception('Datei ' . $fileName . ' existiert nicht');
68 :
69 0 : $this->file = @fopen($fileName, "rb");
70 0 : $this->fileName = $fileName;
71 0 : }
72 :
73 : /**
74 : * Zurückgeben des Inhalts
75 : *
76 : * @access public
77 : */
78 : public function getContent() {
79 0 : $inhalt = fread($this->file, filesize($this->fileName));
80 :
81 : // Streams (zwischen 'stream' und 'endstream') aus der PDF-Datei auslesen
82 0 : $streams = array();
83 0 : preg_match_all("/(stream)(.+)(endstream)/Us", $inhalt, $streams);
84 :
85 0 : $pdf_textinhalt = "";
86 :
87 0 : foreach ( $streams[2] as $stream ) {
88 : // Stream dekomprimieren
89 0 : $stream = @gzuncompress(trim($stream));
90 :
91 : // Text-Objekte (zwischen 'BT' und 'ET') auslesen
92 0 : $textObjects = array();
93 0 : preg_match_all("/(^|\n|\r)BT(\n|\r)(.+)(\n|\r)ET(\n|\r|$)/Us", $stream, $textObjects);
94 :
95 : // Text-Objekte zu einem Teil zusammenfügen
96 0 : $textObjects = implode(" ", $textObjects[3]);
97 :
98 : // Strings (zwischen '(' und ')') aus den Text-Objekten auslesen
99 : // vor den Klammern darf kein Backslash stehen, sonst gehören sie selbst zum String
100 0 : $text = array();
101 0 : preg_match_all("/(?<!\\\)\((.+)(?<!\\\)\)/Uis", $textObjects, $text);
102 :
103 : // Strings sind oft einzelne Buchstaben aus Wörtern, daher Zusammenfügen ohne Trenner
104 0 : $text = implode("", $text[1]);
105 :
106 : // Oktalstrings in der Form '\xxx' in ASCII-Zeichen umwandeln
107 0 : $text = preg_replace("/\\\([0-9]{1,3}+)/e", 'chr(octdec("$1"))', $text);
108 0 : $pdf_textinhalt.= $text." ";
109 0 : }
110 :
111 0 : return $pdf_textinhalt;
112 : }
113 :
114 : /**
115 : * Schliessen der Datei
116 : *
117 : * @access public
118 : */
119 : public function close() {
120 0 : }
121 :
122 : /**
123 : * Schliessen der Datei
124 : *
125 : * @access public
126 : */
127 : public function cleanup() {
128 0 : }
129 :
130 : }
|